package com.jhx.mall.app.servlet;

import com.jhx.mall.app.service.DtsCateDetailService;
import com.jhx.mall.app.service.impl.DtsCateDetailServiceImpl;
import com.jhx.mall.entity.DtsCategory;
import com.jhx.mall.util.BaseServlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DtsCategory", value = "/api/cate/catelist")
public class DtsCategoryServlet extends BaseServlet {

    private DtsCateDetailService service=null;

    @Override
    public void init(ServletConfig config)throws ServletException{
        service=new DtsCateDetailServiceImpl();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String opr=request.getParameter("opr");
    if(opr.equals("list")){
        List<DtsCategory> list=service.getCateDetail();
        if(list!=null){
            ok(request,response,list);
        }else {
            error(request,response,list);
        }
    } else if (opr.equals("list2")) {
        Long id= Long.parseLong(request.getParameter("id"));
        List<DtsCategory> list=service.getCateDetail2(id);
        if(list!=null){
            ok(request,response,list);
        }else {
            error(request,response,list);
        }
    }
    }
}